#include "threadB.h"
#include <iostream>
#include <time.h>
#include <stdlib.h>
#include <map>
#include "ThreadManager.h"
#include <Windows.h>

#define random(x) (rand()%x)

using namespace std;


int CThreadB::setID(int id)
{
	m_id = id;
	return 0;
}

int CThreadB::getID()
{
	return m_id;
}

void CThreadB::handleInt(const int& item, const Theron::Address from)
{
	srand((int)time(0));
	printf("CThreadB receive data with int type: %d \n", item);
	int data = random(100);
	Sleep(2000);
	Send(data, from);
}

int CThreadB::send2ThreadbyID(int data, int ID)
{
	map<int, Theron::Address>::iterator iter;
	iter = ThreadManager::instance()->ID_ADDRESS_MAP.find(ID);
	if (iter != ThreadManager::instance()->ID_ADDRESS_MAP.end())
	{
		Send(data, iter->second);
		return 0;
	}

	return -1;
}